from django import forms
import re


class RegisterForm(forms.Form):
    phone = forms.CharField(max_length=11, required=True)
    password = forms.CharField(widget=forms.PasswordInput, required=True, min_length=8, max_length=20)
    username = forms.CharField(required=True, max_length=100)
    id = forms.CharField(required=True, max_length=100)

    def clean_phone(self):
        phone = self.cleaned_data['phone']
        if not re.fullmatch(r"\d{11}", phone):
            raise forms.ValidationError('手机号码格式不正确')
        return phone


class LoginForm(forms.Form):
    phone = forms.CharField(max_length=11, required=True)
    password = forms.CharField(widget=forms.PasswordInput, required=True)
